<%--
  Created by IntelliJ IDEA.
  User: SQB
  Date: 2015/4/22
  Time: 22:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>article list</title>
    <%@include file="tpl/header.jsp" %>
    <style>
        .breadcrumb {
            background: #222222;
        }

        .breadcrumb > li + li:before {
            color: #CCCCCC;
            content: "/ ";
            padding: 0 5px;
        }
    </style>
</head>
<body>
<%@include file="tpl/nav.jsp" %>
<!-- inverse导航栏 -->
<script>
    $(function () {
        if ($("nav").hasClass("navbar-default")) {
            $("nav").addClass("navbar-inverse");
        }
    });
</script>

<c:forEach items="${article}" var="article" varStatus="status">
    <div class="media">
        <a class="pull-left" href="#">
            <img class="media-object" src="http://placehold.it/64x64" alt="...">
        </a>

        <div class="media-body">
            <h4 class="media-heading"><a href="${path}/article/detail/${article.id}">${article.title}</a></h4>

            <span>${article.content}</span>
        </div>
    </div>
</c:forEach>


<style>
    .pagging{
        text-align: center;
    }
</style>
<div class="pagging">
    <ul class="pagination pagination-lg">
        <li class="disabled"><a href="#">&laquo;</a></li>
        <fmt:formatNumber var="totalPage" type="number" value="${(num-num%pageSize)/pageSize+1}" maxFractionDigits="0"/>
        <c:if test="${num%pageSize eq 0}">
            <c:set var="totalPage" value="${num/pageSize}"/>
        </c:if>
        <!-- pageLenth为分页栏的长度，默认为5 -->
        <c:set var="pageLenth" value="5"/>
        <c:choose>
            <c:when test="${totalPage <= pageLenth}">
                <c:forEach var="i" begin="1" end="${totalPage}" varStatus="status">
                    <li
                            <c:if test="${i eq pageNO}">
                                class="active"
                            </c:if>
                            ><a href="${path}/article/${categories}/list?pageNO=${i}&pageSize=${pageLenth}">${i}</a></li>
                </c:forEach>
            </c:when>
            <c:when test="${totalPage > pageLenth && pageNO-(pageLenth+1)/2 <= 1 }">
                <c:forEach var="i" begin="1" end="${pageLenth}" varStatus="status">
                    <li
                            <c:if test="${i eq pageNO}">
                                class="active"
                            </c:if>
                            ><a href="${path}/article/${categories}/list?pageNO=${i}&pageSize=${pageLenth}">${i}</a></li>
                </c:forEach>
            </c:when>
            <c:when test="${totalPage > pageLenth && pageNO-(pageLenth+1)/2 > 1 && pageNO+(pageLenth+1)/2 < totalPage}">
                <c:forEach var="i" begin="${pageNO-(pageLenth+1)/2}" end="${pageNO+(pageLenth+1)/2}" varStatus="status">
                    <li
                            <c:if test="${i eq pageNO}">
                                class="active"
                            </c:if>
                            ><a href="${path}/article/${categories}/list?pageNO=${i}&pageSize=${pageLenth}">${i}</a></li>
                </c:forEach>
            </c:when>
            <c:when test="${totalPage > pageLenth && pageNO+(pageLenth+1)/2 >= totalPage}">
                <c:forEach var="i" begin="${totalPage - pageLenth + 1}" end="${totalPage}" varStatus="status">
                    <li
                            <c:if test="${i eq pageNO}">
                                class="active"
                            </c:if>
                            ><a href="${path}/article/${categories}/list?pageNO=${i}&pageSize=${pageLenth}">${i}</a></li>
                </c:forEach>
            </c:when>
        </c:choose>
      <%--  <c:forEach var="i" begin="1" end="${totalPage}" varStatus="status">
            <li
            <c:if test="${i eq pageNO}">
               class="active"
            </c:if>
            ><a href="${path}/article/${categories}/list?pageNO=${i}&pageSize=5">${i}</a></li>
        </c:forEach>--%>
        <li><a href="">&raquo;</a></li>
    </ul>
</div>
<div style="text-align: center">
    总共<span class="badge">${num}</span>条
</div>
<!-- totalPage jstl formatNumber -->
<%--<fmt:formatNumber var="totalPage" type="number" value="${(num-num%pageSize)/num+1}" maxFractionDigits="0"/>
${totalPage}--%>
<!--div class="media">
    <a class="pull-left" href="#">
        <img class="media-object" src="http://placehold.it/64x64" alt="...">
    </a>
    <div class="media-body">
        <h4 class="media-heading">Media heading</h4>
        <p>Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.</p>
    </div>
</div-->

</body>
</html>

